import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'
import { getProjectListApi, } from '@/api'

const initialState = {
    projectList: [],
}


export const linpingScreenSlice = createSlice({
    name: 'linpingScreen',
    initialState,
    reducers: {
        changeProjectList: (state, { payload }) => {
            state.projectList = payload
        },
    },
})

export const fetchProjectList = createAsyncThunk('fetch/projectList', async (state, store) => {
    const res = await getProjectListApi({ pageSize: 5000, pageIndex: 1, project_status: '' })
    store.dispatch(changeProjectList(res.data.items))
    return res.data
})
export const { changeProjectList } = linpingScreenSlice.actions

export default linpingScreenSlice.reducer